<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lineType']" placeholder="请输入线别"></a-input>
        </a-form-item>
        <a-form-item label="日期/班别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['classType']" placeholder="请输入日期/班别"></a-input>
        </a-form-item>
        <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['customerName']" placeholder="请输入客户名称"></a-input>
        </a-form-item>
        <a-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productName']" placeholder="请输入产品名称"></a-input>
        </a-form-item>
        <a-form-item label="软件版本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['softwareVersion']" placeholder="请输入软件版本"></a-input>
        </a-form-item>
        <a-form-item label="生产任务单" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productNum']" placeholder="请输入生产任务单"></a-input>
        </a-form-item>
        <a-form-item label="BOM" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productBom']" placeholder="请输入BOM"></a-input>
        </a-form-item>
        <a-form-item label="芯片型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['chipType']" placeholder="请输入芯片型号"></a-input>
        </a-form-item>
        <a-form-item label="LED灯颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ledColor']" placeholder="请输入LED灯颜色"></a-input>
        </a-form-item>
        <a-form-item label="批量/样本数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['samplesNum']" placeholder="请输入批量/样本数"></a-input>
        </a-form-item>
        <a-form-item label="PCB周期/版本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pcbCycle']" placeholder="请输入PCB周期/版本"></a-input>
        </a-form-item>
        <a-form-item label="工艺要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['techReq']" placeholder="请输入工艺要求"></a-input>
        </a-form-item>
        <a-form-item label="首件类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['firstType']" placeholder="请输入首件类型"></a-input>
        </a-form-item>
        <a-form-item label="判断结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['judgeResult']" placeholder="请输入判断结果"></a-input>
        </a-form-item>
        <a-form-item label="备用1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query1']" placeholder="请输入备用1"></a-input>
        </a-form-item>
        <a-form-item label="备用2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query2']" placeholder="请输入备用2"></a-input>
        </a-form-item>
        <a-form-item label="备用3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query3']" placeholder="请输入备用3"></a-input>
        </a-form-item>
        <a-form-item label="备用4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query4']" placeholder="请输入备用4"></a-input>
        </a-form-item>
        <a-form-item label="备用5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query5']" placeholder="请输入备用5"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  
  export default {
    name: "FirstPieceSmtModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/produce/firstPieceSmt/add",
          edit: "/produce/firstPieceSmt/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'lineType','classType','customerName','productName','softwareVersion','productNum','productBom','chipType','ledColor','samplesNum','pcbCycle','techReq','firstType','judgeResult','query1','query2','query3','query4','query5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'lineType','classType','customerName','productName','softwareVersion','productNum','productBom','chipType','ledColor','samplesNum','pcbCycle','techReq','firstType','judgeResult','query1','query2','query3','query4','query5'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>